<template>
    <div id="header">
        <input type="checkbox" v-model="checkedAll" @click="checkAll">
    </div>
</template>

<script setup>
import { ref, watch } from 'vue'
import emitter from '../eventBus.js'
const datas = ref([])
// 接受datas数据
emitter.on('datasContent', (data) => {
    datas.value = data.value || data
})

let checkedAll = ref(false)
// 全选
const checkAll = () => {
    checkedAll.value = !checkedAll.value
    datas.value.forEach(item => {
        item.isChecked = checkedAll.value
    });
}
// 监听datas的数据判断是否全选
watch(datas, () => {
    checkedAll.value = datas.value.every(item => item.isChecked);
}, { deep: true })
</script>